﻿Partial Public Class SiteExplorer

    Public Overridable Sub TreeActionOptionListLoad()

    End Sub

    Public Overridable Sub ProcessCurrentMasterRecord(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs)
        Throw New NotImplementedException
    End Sub

    Public Overridable Sub Site_ValidateDetailRow(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs)
        Dim row As DataRow = CType(e.Row, DataRowView).Row

        If row IsNot Nothing AndAlso row.Table.TableName = "SiteEquipment" Then
            Using plEquipmentSite As SystemBoxSDK.PL.CoreSDK.EquipmentSite_PL = New SystemBoxSDK.PL.CoreSDK.EquipmentSite_PL()
                plEquipmentSite.ValidateRow(row)
            End Using
        End If

    End Sub

    Public Overridable Sub ValidateMasterRow(sender As Object, e As Views.Base.ValidateRowEventArgs)
        Dim view As GridView = CType(sender, GridView)
        Dim row As DataRow = view.GetFocusedDataRow()

        If IsDBNull(row("SocietyID_FK")) Then
            row.SetColumnError("SocietyID_FK", "Mandatory")
        End If

    End Sub

    Public Overridable Sub ValidateDetailRow(sender As Object, e As Views.Base.ValidateRowEventArgs)
        Dim view As GridView = CType(sender, GridView)
        Dim row As DataRow = view.GetFocusedDataRow()

    End Sub

    Public Overridable Sub InitNewMasterRow(sender As Object, e As InitNewRowEventArgs)
        Dim view As GridView = CType(sender, GridView)
        Dim row As DataRow = view.GetFocusedDataRow()
        Using Site As SystemBoxSDK.PL.MESSDK.Site_PL = New SystemBoxSDK.PL.MESSDK.Site_PL()
            Site.NewRecord(row)
        End Using

    End Sub

    Public Overridable Sub InitNewDetailRow(sender As Object, e As InitNewRowEventArgs)
        Throw New NotImplementedException
    End Sub

    Public Overridable Sub ProcessCurrentDetailRecord(sender As Object, e As Views.Base.ValidateRowEventArgs, index As Integer)
        Throw New NotImplementedException
    End Sub

    Public Overridable Sub DetailCellValueChanged(sender As Object, e As Views.Base.CellValueChangedEventArgs)
        Throw New NotImplementedException
    End Sub

    Public Overridable Sub MasterRowClick(sender As Object, e As RowClickEventArgs)
        Throw New NotImplementedException
    End Sub

    Public Overridable Sub DetailRowClick(sender As Object, e As RowClickEventArgs)
        Throw New NotImplementedException
    End Sub

    Public Overridable Sub DetailCustomRowCellEditForEditing(sender As Object, e As CustomRowCellEditEventArgs)
        Throw New NotImplementedException
    End Sub

    Public Overridable Sub SiteDetail_CustomRowCellEditForEditing(ByVal sender As Object, ByVal e As CustomRowCellEditEventArgs)
        Dim aView As GridView = DirectCast(sender, GridView)
        Dim aRTEdit As RepositoryItemButtonRichTextEditExt
        Dim aLov As New RepositoryItemGridLookUpEdit()

        Dim aRow As DataRow = aView.GetFocusedDataRow()

        If aView.Tag.ToString = "SocietyActivity" Then
            If Not IsNothing(aView.Columns("ProjectDocument")) Then
                If e.Column.FieldName = "ProjectDocument" Then
                    aRTEdit = New RepositoryItemButtonRichTextEditExt

                    If e.CellValue Is Nothing Then
                        aRTEdit.Text = String.Empty
                    Else
                        aRTEdit.Text = e.CellValue.ToString
                    End If

                    aView.GridControl.RepositoryItems.Add(aRTEdit)
                    e.RepositoryItem = aRTEdit
                End If
            End If
        End If


    End Sub


    Private Sub Site_InitNewDetailRow(sender As Object, e As InitNewRowEventArgs)
        Dim view As GridView = CType(sender, GridView)
        Dim row As DataRow = view.GetFocusedDataRow()

        Select Case row.Table.TableName
            Case "SiteEquipment"
                row("EquipmentSiteId") = Guid.NewGuid
                row("InspectionRate") = 1
                row("AmortRate") = 0
                row("Capacity") = 0
                row("ByDefault") = 0
                row("Inactive") = 0
            Case "SiteSection"
                row("SiteSectionId") = Guid.NewGuid
                row("SystemRecord") = 0
                row("Inactive") = 0
            Case "SiteItemMaster"
                row("ItemMasterID") = Guid.NewGuid

        End Select




    End Sub

End Class
